import i18n from '@src/locales';
import { getRootWindow } from '@src/util/dom';
// 是否开启云仓灰度
const isCloudwarehouse = () => {
  const RootWindow = getRootWindow(window)
  return RootWindow.grayAuth?.cloudwarehouse || false
}

const goodsFields = [{
  tableName: 'goods',
  fieldName: 'base_info',
  displayName: i18n.t('common.base.basicInfo'),
  formType: 'separator',
  orderId: 0,
  isEdit: 1,
  show: false,
  isDelete: 0,
  isGuideData: true,
  isHidden: 0,
  isNull: 1,
  isSearch: 0,
  isSystem: 0,
  isVisible: true,
  placeHolder: '',
  setting: {
    isAuthorization: false
  },
  subFormFieldList: null,
}, {
  tableName: 'goods',
  isSystem: 1,
  fieldName: 'commodityName',
  displayName: i18n.t('goods.component.tradeName'),
  formType: 'text',
  defaultValue: null,
  isNull: 0,
  isSearch: 0,
  placeHolder: i18n.t('order.placeHolder.productName'),
  setting: {},
  maxlength: 50,
  orderId: 1,
  isDelete: 0,
  isEdit: 1,
  guideProfessions: [],
  show: true,
  export: true,
  isGuideData: false,
  guideData: false,
}, {
  tableName: 'goods',
  isSystem: 1,
  fieldName: 'originType',
  displayName: i18n.t('order.detailV2.productType'),
  formType: 'select',
  defaultValue: null,
  isNull: 0, // 是否开启校验
  isSearch: 1,
  operator: 'eq',
  setting: {
    isMulti: false,
    dataSource: [{
      text: i18n.t('common.base.sparePart'),
      value: 1,
    }, {
      text: i18n.t('common.form.type.material'),
      value: 3,
    }, {
      text: i18n.t('common.label.serviceItem'),
      value: 2,
    }],
  },
  orderId: 2,
  isDelete: 0,
  isEdit: 1, // 是否在编辑页显示
  guideProfessions: [],
  show: true, // 是否在列表页显示
  export: true, // 是否可以导出
  isGuideData: false,
  guideData: false,
}, {
  tableName: 'goods',
  isSystem: 1,
  fieldName: 'attachmentList',
  displayName: i18n.t('order.productImg'),
  formType: 'attachment',
  defaultValue: null,
  isNull: 0,
  isSearch: 0,
  placeHolder: null,
  setting: {},
  orderId: 1,
  isDelete: 0,
  isEdit: 1,
  guideProfessions: [],
  show: true,
  export: false,
  isGuideData: false,
  guideData: false,
}, {
  tableName: 'goods',
  isSystem: 1,
  fieldName: 'commodityCode',
  displayName: i18n.t('common.base.goodsNo'),
  formType: 'text',
  defaultValue: null,
  isNull: 0,
  isSearch: 0,
  placeHolder: i18n.t('common.fields.productNo.placeholder'),
  setting: {},
  show: true,
  export: true,
  orderId: 0,
  isDelete: 0,
  isEdit: 1,
  disabled: 1,
  guideProfessions: [],
  isGuideData: false,
  guideData: false,
}, {
  tableName: 'goods',
  isSystem: 1,
  fieldName: 'originCode',
  displayName: isCloudwarehouse() ? i18n.t('product.materialFields.sn.displayName') : i18n.t('common.part.partNo'),
  formType: 'text',
  defaultValue: null,
  isNull: 0,
  isSearch: 0,
  placeHolder: i18n.t('common.fields.productNo.placeholder'),
  setting: {},
  show: true,
  export: true,
  orderId: 0,
  isDelete: 0,
  isEdit: 1,
  disabled: 1,
  guideProfessions: [],
  isGuideData: false,
  guideData: false,
}, {
  tableName: 'goods',
  isSystem: 1,
  fieldName: 'originName',
  displayName: i18n.t('order.serviceItemName'),
  formType: 'text',
  defaultValue: null,
  isNull: 0,
  isSearch: 0,
  placeHolder: i18n.t('order.placeHolder.productName'),
  setting: {},
  orderId: 0,
  isDelete: 0,
  isEdit: 1,
  guideProfessions: [],
  show: false,
  export: false,
  isGuideData: false,
  guideData: false,
}, {
  tableName: 'goods',
  isSystem: 1,
  fieldName: 'originCategory',
  displayName: i18n.t('common.fields.catalog.displayName'),
  formType: 'select',
  defaultValue: null,
  export: false,
  isNull: 0,
  isSearch: 1,
  operator: 'eq',
  setting: {
    isMulti: false,
    dataSource: [],
  },
  orderId: 3,
  isDelete: 0,
  isEdit: 1,
  guideProfessions: [],
  show: true,
  export: true,
  isGuideData: false,
  guideData: false,
}, {
  tableName: 'goods',
  isSystem: 1,
  fieldName: 'productTypeList',
  displayName: i18n.t('common.label.ralationProductType'),
  formType: 'select',
  defaultValue: null,
  isNull: 1,
  isSearch: 0,
  placeHolder: i18n.t('common.placeholder.selectProductType'),
  setting: {},
  orderId: 10,
  isDelete: 0,
  isEdit: 1,
  guideProfessions: [],
  show: true,
  export: true,
  isGuideData: false,
  guideData: false,
}, {
  tableName: 'goods',
  isSystem: 1,
  fieldName: 'purchaseLink',
  displayName: i18n.t('order.purchaseLink'),
  formType: 'text',
  defaultValue: null,
  isNull: 1,
  isSearch: 0,
  placeHolder: i18n.t('order.placeHolder.purchaseLinkText'),
  setting: {},
  orderId: 11,
  isDelete: 0,
  isEdit: 1,
  guideProfessions: [],
  show: true,
  export: true,
  isGuideData: false,
  guideData: false,
}, {
  tableName: 'goods',
  isSystem: 1,
  fieldName: 'information',
  displayName: i18n.t('order.productDesc'),
  formType: 'textarea',
  defaultValue: null,
  isNull: 1,
  isSearch: 0,
  placeHolder: i18n.t('order.productDesc'),
  setting: {},
  orderId: 0,
  isDelete: 0,
  isEdit: 1,
  guideProfessions: [],
  show: false,
  export: false,
  isGuideData: false,
  guideData: false,
  maxlength: 200,
}, {
  tableName: 'goods',
  isSystem: 1,
  fieldName: 'displayName',
  displayName: i18n.t('common.base.createUser'),
  formType: 'user',
  defaultValue: null,
  isNull: 0,
  isSearch: 0,
  placeHolder: null,
  setting: {},
  orderId: 1,
  isDelete: 0,
  isEdit: 0,
  guideProfessions: [],
  show: true,
  export: true,
  isGuideData: false,
  guideData: false,
}, {
  tableName: 'goods',
  isSystem: 1,
  fieldName: 'createTime',
  displayName: i18n.t('common.base.createTime'),
  formType: 'datetime',
  defaultValue: null,
  isNull: 0,
  isSearch: 0,
  placeHolder: null,
  setting: {},
  orderId: 12,
  isDelete: 0,
  isEdit: 0,
  guideProfessions: [],
  show: true,
  export: true,
  isGuideData: false,
  guideData: false,
}, {
  tableName: 'goods',
  isSystem: 1,
  fieldName: 'putawayStatus',
  displayName: i18n.t('order.productStatus'),
  formType: 'text',
  defaultValue: null,
  isNull: 0,
  isSearch: 0,
  placeHolder: null,
  setting: {},
  orderId: 8,
  isDelete: 0,
  isEdit: 0,
  guideProfessions: [],
  show: true,
  export: true,
  isGuideData: false,
  guideData: false,
}, {
  tableName: 'goods',
  isSystem: 1,
  fieldName: 'viewNumber',
  displayName: i18n.t('wiki.list.sortLabel.label1'),
  formType: 'text',
  defaultValue: null,
  isNull: 0,
  isSearch: 0,
  placeHolder: null,
  setting: {},
  orderId: 0,
  isDelete: 0,
  guideProfessions: [],
  show: false,
  export: false,
  isGuideData: false,
  guideData: false,
}, {
  tableName: 'goods',
  fieldName: 'price_inventory',
  displayName: i18n.t('order.priceInventory'),
  formType: 'separator',
  orderId: 0,
  isEdit: 1,
  show: false,
  isDelete: 0,
  isGuideData: true,
  isHidden: 0,
  isNull: 1,
  isSearch: 0,
  isSystem: 0,
  isVisible: true,
  placeHolder: '',
  setting: {
    isAuthorization: false
  },
  subFormFieldList: null,
}, {
  tableName: 'goods',
  isSystem: 1,
  fieldName: 'standardDesc',
  displayName: i18n.t('goods.component.isHaveSpecs'),
  formType: 'standardDesc',
  defaultValue: null,
  isNull: 0,
  isSearch: 0,
  placeHolder: '',
  setting: {},
  orderId: 4,
  isDelete: 0,
  isEdit: 1,
  guideProfessions: [],
  show: true,
  export: true,
  isGuideData: false,
  guideData: false,
},
{
  tableName: 'goods',
  isSystem: 1,
  fieldName: 'specsPrice',
  displayName: i18n.t('goods.component.price'),
  formType: 'text',
  defaultValue: null,
  isNull: 0,
  isSearch: 0,
  placeHolder: null,
  setting: {
  },
  orderId: 5,
  isDelete: 0,
  isEdit: 1,
  guideProfessions: [],
  show: false,
  export: false,
  isGuideData: false,
  guideData: false,
  disabled: 1,
},
{
  tableName: 'goods',
  isSystem: 1,
  fieldName: 'price',
  displayName: i18n.t('goods.component.price'),
  formType: 'number',
  defaultValue: null,
  isNull: 0,
  isSearch: 0,
  placeHolder: null,
  setting: {
    limitConig: {
      isLimit: 0,
      type: 1,
      min: 0.01,
      max: 99999
    }
  },
  orderId: 5,
  isDelete: 0,
  isEdit: 1,
  guideProfessions: [],
  show: true,
  export: true,
  isGuideData: false,
  guideData: false,
}, {
  tableName: 'goods',
  isSystem: 1,
  fieldName: 'originPrice',
  displayName: i18n.t('order.serviceItemPrice'),
  formType: 'number',
  defaultValue: null,
  isNull: 0,
  isSearch: 0,
  placeHolder: i18n.t('goods.edit.modifyPrice1'),
  setting: {},
  orderId: 5,
  isDelete: 0,
  isEdit: 1,
  guideProfessions: [],
  show: false,
  export: false,
  isGuideData: false,
  guideData: false,
  disabled: true,
}, {
  tableName: 'goods',
  isSystem: 1,
  fieldName: 'inventoryNumber',
  displayName: i18n.t('common.part.stock'),
  formType: 'number',
  defaultValue: 0,
  isNull: 0,
  isSearch: 0,
  placeHolder: null,
  setting: {
    // limitConig: {
    //   isLimit: 0,
    //   type: 1,
    //   min: 0,
    //   max: 99999
    // }
  },
  orderId: 6,
  isDelete: 0,
  isEdit: 1,
  guideProfessions: [],
  show: true,
  export: true,
  isGuideData: false,
  guideData: false,
}, {
  tableName: 'goods',
  isSystem: 1,
  fieldName: 'saleNumber',
  displayName: i18n.t('order.salesVolume'),
  formType: 'text',
  defaultValue: null,
  isNull: 0,
  isSearch: 0,
  placeHolder: null,
  setting: {},
  orderId: 9,
  isDelete: 0,
  isEdit: 0,
  guideProfessions: [],
  show: true,
  export: true,
  isGuideData: false,
  guideData: false,
}, {
  tableName: 'goods',
  fieldName: 'logistics_info',
  displayName: i18n.t('common.form.preview.sparepart.colum16'),
  formType: 'separator',
  orderId: 0,
  isEdit: 1,
  id: 11111,
  show: false,
  isDelete: 0,
  isGuideData: true,
  isHidden: 0,
  isNull: 1,
  isSearch: 0,
  isSystem: 0,
  isVisible: true,
  placeHolder: '',
  setting: {
    isAuthorization: false
  },
  subFormFieldList: null,
}, {
  tableName: 'goods',
  isSystem: 1,
  fieldName: 'serviceType',
  displayName: i18n.t('order.detailV2.serviceMethod'),
  formType: 'select',
  defaultValue: null,
  isNull: 0,
  isSearch: 0,
  placeHolder: i18n.t('order.placeHolder.serviceMethod'),
  setting: {
    isMulti: true,
    selectType: 2,
    dataSource: [{
      text: i18n.t('goods.component.expressDelivery'),
      value: 1,
    },
    {
      text: i18n.t('task.setting.taskTypeSetting.manage.industryNames.name7'),
      value: 2,
    },
    ],
  },
  orderId: 7,
  isDelete: 0,
  isEdit: 1,
  guideProfessions: [],
  show: true,
  export: true,
  isGuideData: false,
  guideData: false,
}, {
  tableName: 'goods',
  isSystem: 1,
  fieldName: 'expressCost',
  displayName: i18n.t('order.freight'),
  formType: 'number',
  defaultValue: null,
  isNull: 0,
  isSearch: 0,
  placeHolder: null,
  setting: {},
  orderId: 0,
  isDelete: 0,
  isEdit: 1,
  guideProfessions: [],
  show: false,
  export: false,
  isGuideData: false,
  guideData: false,
}, {
  tableName: 'goods',
  isSystem: 1,
  fieldName: 'serviceCost',
  displayName: i18n.t('order.onSiteServiceFee'),
  formType: 'number',
  defaultValue: null,
  isNull: 1,
  isSearch: 0,
  placeHolder: null,
  setting: {},
  orderId: 0,
  isDelete: 0,
  isEdit: 1,
  guideProfessions: [],
  show: false,
  export: false,
  isGuideData: false,
  guideData: false,
},{
  tableName: 'goods',
  isSystem: 1,
  fieldName: 'isAppointmentSupported',
  displayName: i18n.t('order.isAppointmentSupported'),
  formType: 'select',
  defaultValue: null,
  isNull: 1,
  isSearch: 0,
  placeHolder: null,
  orderId: 0,
  isDelete: 0,
  isEdit: 1,
  guideProfessions: [],
  show: false,
  export: false,
  isGuideData: false,
  guideData: false,
}, {
  tableName: 'goods',
  isSystem: 1,
  fieldName: 'hasInventory',
  displayName: i18n.t('order.isHaveInventory'),
  formType: 'select',
  defaultValue: null,
  export: false,
  isNull: 0,
  isSearch: 1,
  operator: 'contain',
  setting: {
    isMulti: false,
    dataSource: [{
      text: i18n.t('common.base.hasState.0'),
      value: 1,
    },
    {
      text: i18n.t('common.base.null'),
      value: 0,
    },
    ],
  },
  orderId: 0,
  isDelete: 0,
  isEdit: 0,
  guideProfessions: [],
  show: false,
  export: false,
  isGuideData: false,
  guideData: false,
}]

const orderFields = [{
  tableName: 'order',
  isSystem: 1,
  fieldName: 'serviceType',
  displayName: i18n.t('order.detailV2.serviceMethod'),
  formType: 'select',
  defaultValue: null,
  isNull: 0, // 是否开启校验
  isSearch: 1,
  operator: 'eq',
  setting: {
    isMulti: false,
    dataSource: [{
      text: i18n.t('goods.component.expressDelivery'),
      value: 1,
    }, {
      text: i18n.t('task.setting.taskTypeSetting.manage.industryNames.name7'),
      value: 2,
    }],
  },
  orderId: 0,
  isDelete: 0,
  isEdit: 1, // 是否在编辑页显示
  guideProfessions: [],
  show: true, // 是否在列表页显示
  export: true, // 是否可以导出
  isGuideData: false,
  guideData: false,
}, {
  tableName: 'order',
  isSystem: 1,
  fieldName: 'originType',
  displayName: i18n.t('order.detailV2.productType'),
  formType: 'select',
  defaultValue: null,
  isNull: 0, // 是否开启校验
  isSearch: 1,
  operator: 'eq',
  setting: {
    isMulti: false,
    dataSource: [{
      text: i18n.t('common.base.sparePart'),
      value: 1,
    }, {
      text: i18n.t('common.fields.serviceName.displayName'),
      value: 2,
    }],
  },
  orderId: 0,
  isDelete: 0,
  isEdit: 1, // 是否在编辑页显示
  guideProfessions: [],
  show: true, // 是否在列表页显示
  export: true, // 是否可以导出
  isGuideData: false,
  guideData: false,
}, {
  displayName: i18n.t('order.detailV2.orderTime'),
  fieldName: 'orderTime',
  formType: 'datetime',
  export: false,
  isNull: 1,
  isSystem: 1,
  operator: 'between',
  orderId: -2,
  tableName: 'order',
}, {
  tableName: 'order',
  isSystem: 1,
  fieldName: 'payType',
  displayName: i18n.t('common.form.preview.pay.payMethod'),
  formType: 'select',
  defaultValue: null,
  isNull: 0, // 是否开启校验
  isSearch: 1,
  operator: 'eq',
  setting: {
    isMulti: false,
    dataSource: [{
      text: i18n.t('order.detailV2.weChatPayment'),
      value: 1,
    }, {
      text: i18n.t('order.detailV2.alipayPayment'),
      value: 2,
    }, {
      text: i18n.t('order.listV2.limitSettlement'),
      value: 3,
    }],
  },
  orderId: 0,
  isDelete: 0,
  isEdit: 1, // 是否在编辑页显示
  guideProfessions: [],
  show: true, // 是否在列表页显示
  export: true, // 是否可以导出
  isGuideData: false,
  guideData: false,
}]

const formatFields = (configFields) => {
  let obj = {};

  const Fields = configFields.map(field => {
    return Object.assign({
      ...field,
      isNull: 1,
      formType: field.formType,
      originalFormType: field.formType,
    });
  }).sort((a, b) => a.orderId - b.orderId)
    .reduce((item, next) => {
      // 过滤掉相同fieldName的字段 去重
      obj[next.fieldName] ? '' : obj[next.fieldName] = true && item.push(next);
      return item;
    }, []);

  return Fields;
}

const otherFields = [
  {
    tableName: 'goods',
    isSystem: 1,
    fieldName: 'specsDesc',
    displayName: i18n.t('goods.component.productSpecifications'),
    formType: 'specsDesc',
    defaultValue: null,
    isNull: 0,
    isSearch: 0,
    placeHolder: '',
    setting: {},
    orderId: 4,
    isDelete: 0,
    isEdit: 1,
    guideProfessions: [],
    show: true,
    export: true,
    isGuideData: false,
    guideData: false,
  }, 
  {
    tableName: 'goods',
    isSystem: 1,
    fieldName: 'standard',
    displayName: i18n.t('goods.component.specificationDesc'),
    formType: 'standard',
    defaultValue: null,
    isNull: 0,
    isSearch: 0,
    placeHolder: '',
    setting: {},
    orderId: 10,
    isDelete: 0,
    isEdit: 1,
    guideProfessions: [],
    show: true,
    export: true,
    isGuideData: false,
    guideData: false,
  }, 
]
export {
  goodsFields,
  orderFields,
  formatFields,
  otherFields
}
